package sender
import java.sql.*;
import groovy.sql.Sql
import java.lang.reflect.Array;
import org.apache.commons.mail.EmailAttachment;
import org.apache.commons.mail.MultiPartEmail;
import com.gmongo.GMongo
class EmailSender {
	
	def   sendEmail(def username){
		MultiPartEmail multipartemail = new MultiPartEmail();
		if(username['type']=="qq"){
			multipartemail.setHostName("smtp.qq.com");
		}else if(username['type']=="163"){
			multipartemail.setHostName("smtp.163.com");
		}else if(username['type']=="gmail"){
			multipartemail.setSSL(Boolean.TRUE);
			multipartemail.setSslSmtpPort("465");
			multipartemail.setHostName("smtp.gmail.com");
		}else{
			multipartemail.setSSL(Boolean.TRUE);
			multipartemail.setSslSmtpPort("465");
			multipartemail.setHostName("smtp.gmail.com");
		}
		multipartemail.addTo(username['sendto'], username['username']);
		multipartemail.setFrom(username['user'], username['name']);
		multipartemail.setAuthentication(username['user'], username['psw']);
		multipartemail.setSubject(username['subject']);
		
		if(username['file']==null){
			multipartemail.setContent(username['content'], "text/html;charset=GBK")
		}else{
			multipartemail.setMsg(username['content'])
			EmailAttachment emailattachment = new EmailAttachment();
			emailattachment.setPath(username['file']);
			//			emailattachment.setDisposition(EmailAttachment.ATTACHMENT);
			//			emailattachment.setDescription("This is Smile picture");
			//			emailattachment.setName("img.jpg");
		}
		
		multipartemail.attach(emailattachment);
		
		multipartemail.send();
	}
}
